package cn.lanqiao.ui;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

import cn.lanqiao.entiy.Teacher;
import cn.lanqiao.service.TeacherService;
import cn.lanqiao.service.impl.TeacherServiceImpl;


import javax.swing.JScrollPane;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TeacherListFrm extends JInternalFrame {
	private JTable table;
	Teacher teacher=null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TeacherListFrm frame = new TeacherListFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TeacherListFrm() {
		setTitle("教练列表");
	
		setClosable(true);
		setBounds(100, 100, 882, 533);
		getContentPane().setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 0, 866, 398);
		getContentPane().add(scrollPane);
	
        
		
		//导入教练表数据
		String[] header =new String[] {"编号","姓名","性别","职务","账号","电话"};
		TeacherService teachser=new TeacherServiceImpl();
		Object[][] teachlist= teachser.getTeacherList();
		table = new JTable();
		table.setModel(new DefaultTableModel(teachlist,header));
		scrollPane.setViewportView(table);
		
		JButton btnNewButton = new JButton("选择教练");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//判断用户是否选中教练
				int rowIndex=table.getSelectedRow();
				System.out.println(rowIndex);
				if(rowIndex==-1) {
					JOptionPane.showMessageDialog(null, "请选择教练");
					return;
				}
				//获取教练信息;选择教练
				String id,name,sex,job,nick,uid,telpho;
				id=table.getValueAt(rowIndex, 0).toString();
				name=table.getValueAt(rowIndex, 1).toString();
				sex=table.getValueAt(rowIndex, 2).toString();
				job=table.getValueAt(rowIndex, 3).toString();
				uid=table.getValueAt(rowIndex, 4).toString();
				telpho=table.getValueAt(rowIndex, 5).toString();
			
			  teacher=new Teacher(id, name, sex, job, uid, telpho);
//			  System.out.println(teacher);
			  //是否报名
			  int val= JOptionPane.showConfirmDialog(null,"是否报名", "报名选择",JOptionPane.YES_NO_OPTION);
			  System.out.println(val);
			  if(val==0) {
				  StudentApplyImformationFrm saf=new StudentApplyImformationFrm();
				  saf.setVisible(true);
			       return;
			  }
			}
		});
		btnNewButton.setBounds(715, 436, 93, 23);
		getContentPane().add(btnNewButton);
		
		
	
		
	
		
		
	
	}
}
